<?php

namespace App\Admin\Exports\Sheet;

use App\Models\Category\Category;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithTitle;

class CategorySheet implements FromCollection, WithHeadings, WithTitle
{
    public function collection()
    {
        $fields = array_keys(config('rj-excel-export.category.fields', [
            'id', 'name', 'image', 'parent_id', 'isbn', 'unit_main_name', 'unit_name', 'module'
        ]));

        return Category::query()->select($fields)->get();
    }

    public function headings(): array
    {
        return array_values(config('rj-excel-export.category.fields', [
            '书籍编号', '书籍名称', '封面图片', '父级ID', 'ISBN编号', '单元主名称', '单元副标题', '模块文件名'
        ]));
    }

    public function title(): string
    {
        return config('rj-excel-export.category.sheet_title', '书籍');
    }
}
